﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using ZLDC.Topo.Model.Estate;

namespace ZLDC.Estate.PM
{
    public partial class HousingLockInput : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
                int id =_Convert.ToInt(IDList[0]);
                HousingInfo info = CacheHousing.Cache_Detail_Info(id);
                string allchildrenDept = _Utility.GetInfoBySession().m_sChildrenDeptList;

                if (info != null)
                {
                    sEname.InnerText = info.Ename + info.BuildName + info.Mark1 + info.RoomNo;

                    if (!allchildrenDept.Contains(info.MarkUDeptId.ToString())) //判断是否是本部门的盘源
                    {
                        ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('无权封此分行的盘源!');window.close();</script>");
                        return;
                    }

                    if (info.Protected==1)//判断是否已经封盘
                    {
                        string protectedClass = ZLDC.Topo.BLL.Estate.HousingExtendBLL.p_Housing_Extend_List(id);
                        string sMsg = "该盘已经设置了封盘:" + protectedClass + "可查看电话";
                        ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('"+sMsg+"');window.close();</script>");
                        return;
                    }
                }
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            for (int i = 0; i < IDList.Length; i++)
            {
                if (_Convert.ToInt(IDList[i]) <= 0)
                    return;
                string RoleName = "";
                if (rboManager1.Checked)
                    RoleName = "分行经理";
                else
                    RoleName = "区域经理";

                //0提前解封 1封盘
                string outmsg = ZLDC.Topo.BLL.Estate.HousingBLL.HousingLock(_Convert.ToInt(IDList[i]), 1);
                if (outmsg == "封盘成功")
                {
                    outmsg = ZLDC.Topo.BLL.Estate.HousingExtendBLL.p_Housing_Extend_insert(_Convert.ToInt(IDList[i]), RoleName);//设置查看封盘电话的权限
                }

                // 更新缓存
                if (_Convert.ToInt(IDList[i]) > 0)
                {
                    _Cache.Remove(CacheConst.CACHE_HOUSING_DETAIL_JSON + IDList[i].ToString());
                    _Cache.Remove(CacheConst.CACHE_HOUSING_DETAIL_INFO + IDList[i].ToString());
                    _Cache.RemoveLike(CacheConst.CACHE_HOUSING_FOLLOW_JSON + IDList[i].ToString()); // 清空缓存
                }
   
            }
            ClientScript.RegisterStartupScript(typeof(string), "", "<script>window.close();</script>");


        }
    }
}
